Skip to content

fix(framework): harden admin RPC, signature caching and peer tests - #7137

Open
317787106 wants to merge 5 commits into
tronprotocol:release_v4.8.3from
317787106:fix/admin_endpoint
Open

317787106 wants to merge 5 commits into
tronprotocol:release_v4.8.3from
317787106:fix/admin_endpoint

Conversation

@317787106

@317787106 317787106 commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

  1. Reject unknown Admin JSON-RPC method names before entering jsonrpc4j reflection lookup, for both HTTP and IPC. Preserve @JsonRpcMethod(required = true) semantics, response IDs, and empty responses for notifications.
  2. Clear TransactionCapsule.isVerified when setRawData() replaces signed transaction data. Add regressions covering reference blocks, expiration, both timestamp setters, and fee limits.
  3. Replace Channel spies in ResilienceServiceTest and PeerStatusCheckTest with ordinary Channel fixtures and stub-only transport contexts. Reset the raw peer pool, connection counters, and executor during teardown, including already-disconnected peers.

Why are these changes required?

Unknown Admin method names previously reached jsonrpc4j's unbounded static reflection cache, retaining a new entry for every distinct name even when the request returned -32601 or was a silent notification.

A successful signature-verification result applies to the original raw transaction data. Keeping isVerified = true after changing that data lets the same capsule skip verification of the modified transaction.

In network tests, repeated status queries accumulated Mockito spy invocation records, while cleanup through the filtered active-peer list left disconnected peers in the static pool .

This PR has been tested by:

Local validation on macOS ARM64 / JDK 17:

Follow up

CI validation across the supported platform matrix.

Extra details

Admin method names are collected from the API interface and its annotations rather than maintained in a separate hard-coded list.

Reject method names outside the Admin API before invoking jsonrpc4j to
prevent unknown requests and notifications from growing its static cache.
Preserve annotated-name requirements and request ID semantics.

Add HTTP and IPC regressions for unknown names, Java aliases, and
notification requests.

Refs: JT-971
Use real Channel fixtures with stub-only transport contexts so status
queries do not retain Mockito invocation histories.

Reset the raw peer pool, connection counters, and executor during teardown
in ResilienceServiceTest and PeerStatusCheckTest. Cover disconnected-peer
cleanup with a regression test.

Refs: JT-283
Clear the verified flag whenever raw transaction data is replaced.

Verify that changes to references, expiration, both timestamp setters,
and fee limits invalidate the transaction ID and signature cache, and
reject signatures created for the previous raw data.
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.3 milestone Dec 3, 2026
this.transaction = this.transaction.toBuilder().setRawData(rawData).build();
// invalidate trxId
this.id = null;
setVerified(false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SHOULD] Invalidate the cached verification result when appending a signature.

Could sign() also call setVerified(false) after appending a signature?

Although the transaction ID remains unchanged, the cached verification result applies to the previous signature list and should no longer be considered valid.

Please also add a regression test verifying that appending a signature preserves the transaction ID, invalidates the cached verification result, and causes the next validation to evaluate the updated signature list.

@317787106 317787106 Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method public void sign(byte[] privateKey) is not invoked by any production code, but call setVerified(false) is more safe. Fixed it in 9b326ce

// invalidate trxId
// Cached identity and verification are bound to raw_data.
this.id = null;
this.isVerified = false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SHOULD] Synchronize transaction mutations with signature validation to prevent stale verification results.

Could we have setRawData() and sign() synchronize on the same capsule monitor as validateSignature()?

With the current direct flag writes, an in-flight validation can complete after either mutation and set isVerified back to true, even though the verification result applies to the previous transaction contents.

The existing concurrency test calls setVerified(false) directly. Could we extend the regression coverage to exercise the actual mutation paths, specifically setFeeLimit() and sign(), while signature validation is in progress?

Please verify that the cached verification result is invalidated once both operations have completed.

This would ensure that transaction mutations and signature validation are properly serialized, rather than relying solely on resetting the verification flag.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 20c91bf. setRawData() and sign() now synchronize on the same capsule monitor as validateSignature(). Added concurrency regressions exercising setFeeLimit() and sign() during an in-flight validation. They verify that mutations wait for validation and leave isVerified false after both operations complete. Both tests fail without the synchronization.

ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine
.signHash(getTransactionId().getBytes())));
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
this.isVerified = false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NIT] Could we add a test that verifies a signed capsule, calls sign() again, and asserts that isVerified() becomes false while the transaction ID stays the same? The current test signs before the first validation, so it would still pass if this line were removed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 20c91bf. The new test first validates a signed capsule, calls sign() again, and checks that isVerified() becomes false while the transaction ID stays unchanged. It also verifies that the next validation rejects the updated signature list. Confirmed that the test fails if the cache-reset line in sign() is removed.

@317787106
317787106 requested review from 3for and lxcmyf December 3, 2026 05:00
}

private void setRawData(Transaction.raw rawData) {
private synchronized void setRawData(Transaction.raw rawData) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SHOULD] Synchronize transaction ID cache population and invalidation.

Could getTransactionId() synchronize on the same capsule monitor as setRawData()?

On a cache miss, getTransactionId() also writes to id. A concurrent caller could finish hashing the previous raw_data after setRawData() has invalidated the cache, repopulating it with a stale transaction ID.

Using the same monitor would serialize cache population and invalidation, ensuring that the cached transaction ID remains consistent with the current raw_data.

Could we also add a concurrency regression test covering this race and verify that the cached transaction ID matches the updated raw_data once both operations complete?

@3for

3for commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

[SHOULD, FOLLOW-UP] Document the concurrency contract of TransactionCapsule.

As a follow-up, could we document which operations callers may safely perform concurrently on the same TransactionCapsule instance and which require external synchronization?

For example, removeRedundantRet() writes back an entire transaction snapshot, while fee-limit updates construct their raw-data snapshot before acquiring the capsule monitor. Synchronizing the final write alone does not prevent concurrent read-modify-write operations from overwriting each other's changes.

Please clarify the supported concurrency guarantees and identify operations that callers must serialize externally.

This would avoid implying that TransactionCapsule is fully thread-safe simply because individual cache operations and mutation methods are synchronized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants